package com.cheung.leetcode.arr;

public class LC374 {

    public static int guessNumber(int n) {
        int left = 1;
        int right = n;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (guess(mid) <= 0) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }

        return left;
    }

    public static int guess(int num) {
        int pick = 6;
        if (num == pick) {
            return 0;
        }
        return num < pick ? 1 : -1;
    }

    public static void main(String[] args) {
        System.out.println(guessNumber(10));
    }
}
